#!/usr/bin/env python3
# -*- coding: utf-8 -*-



from flask import (
        Blueprint,render_template,
        request,flash,redirect,
        url_for
    )


from ..database import User, db
from ..utils import calc_md5

bp = Blueprint('retire', __name__, url_prefix="/retire")


@bp.route('/', methods=["POST","GET"])
def retire():

    if request.method == "POST":
        account = request.form.get("account")
        pwd = request.form.get("pwd")
    
        if not bool(account):
            flash("账号不能为空")
        if not bool(pwd):
            flash("密码不能为空")
        if account and pwd:
            user = User.query.filter_by(name=account).first()
            if user:
                user.e_password = calc_md5(pwd)
                db.session.commit()
                flash("成功")
        
            else:
                flash("账号不存在")

    return render_template('/pages/retire.html')